package com.dlc.shop.systemtest.api.amount;

import com.alibaba.fastjson.JSON;
import com.dlc.shop.bean.param.UserUpdateParam;
import com.dlc.shop.systemtest.constants.Constant;
import com.dlc.shop.systemtest.util.HttpUtil;
import com.dlc.shop.user.common.dto.LevelDetailDto;
import com.dlc.shop.user.common.dto.LevelDto;
import com.dlc.shop.user.common.model.UserLevel;

import java.util.List;

/**
 * @author lanhai
 */
public class UserLevelApi {

    public static void saveOrUpdate(UserLevel userLevel){
        String url = Constant.PLATFORM_URL+"/user/userLevel";
        HttpUtil.put(url,userLevel);
    }

    public static LevelDetailDto getUserLevel(){
        String url = Constant.API_URL + "/p/score/scoreLevel/page?levelType=0";
        LevelDto levelDto = HttpUtil.get(url, LevelDto.class);
        return levelDto.getUserLevel();
    }

    /**
     * 根据等级类型获取等级列表
     * @param userLevelType
     * @return
     */
    public static List<UserLevel> getUserLevelByType(Integer userLevelType){
        String url = Constant.PLATFORM_URL+"/user/userLevel/list?userLevelType="+userLevelType;
        Object reslut = HttpUtil.get(url, Object.class);
        List<UserLevel> userLevels = JSON.parseArray(reslut.toString(), UserLevel.class);
        return userLevels;
    }

    /**
     * 修改用户积分
     */
    public static void updateScore(UserUpdateParam param){
        String url = Constant.PLATFORM_URL+"/user/userLevel/updateScore";
        HttpUtil.put(url, param);

    }

}
